package com.six.controller;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.fasterxml.jackson.annotation.JsonCreator.Mode;
import com.six.pojo.YuDin;
import com.six.pojo.Zuozi;
import com.six.service.ZuoziService;

@Controller
public class Zuozicontroller {
	@Autowired
	private ZuoziService zuoziService;
	@RequestMapping("/zhuozi")
	public ModelAndView getAllZuozi(){
		ModelAndView modelAndView=new ModelAndView("zuozi");
		List<Zuozi> zuozis=zuoziService.Selectzuozi();
		modelAndView.addObject("zuozis", zuozis);
		return modelAndView;
	}
	@RequestMapping("/zhuozi1")
	public ModelAndView getAllZuozi1(){
		ModelAndView modelAndView=new ModelAndView("zuozi1");
		List<Zuozi> zuozis=zuoziService.Selectzuozi();
		modelAndView.addObject("zuozis", zuozis);
		return modelAndView;
	}
	@RequestMapping("allzuo1")
	public ModelAndView getALlzuo(){
		ModelAndView modelAndView=new ModelAndView("allzuo");
		List<Zuozi> zuo=zuoziService.SelectAllzuozi();
		modelAndView.addObject("zuo", zuo);
		return modelAndView;
		
	}
	@RequestMapping("Allyudin")
	public ModelAndView getAllyudin(){
		ModelAndView modelAndView=new ModelAndView("allyudin");
		List<YuDin> yuDins=zuoziService.selectAllYudin();
		modelAndView.addObject("yuDins", yuDins);
		return modelAndView;
	}
	@RequestMapping("deleteyuyue/{yuid}/{tid}")
	public String delete(@PathVariable("yuid")int yuid,@PathVariable("tid")int tid){
		int i=zuoziService.deleteYudin(yuid);
		int x=zuoziService.updatezhuoziwu(tid);
		
		return "redirect:../../Allyudin";
		
	}
	@RequestMapping("deletezuo/{tid}")
	public String  deletezuo(@PathVariable("tid") int tid){
		int i=zuoziService.deleteZuozi(tid);
		return "redirect:../allzuo1";
	}
	@RequestMapping("tianj")
	public ModelAndView tianj(){
		 ModelAndView modelAndView = new ModelAndView("tianjia");
		 return modelAndView;
	}
	@RequestMapping("jia")
	public String jiazuo(int tid){
		int i=zuoziService.addzuozi(tid);
		System.out.println(tid);
		System.out.println(i);
		return "redirect:allzuo1";
	}
	@RequestMapping("/exi")
	public void fin(int tid,HttpServletResponse response) throws IOException{
		 int i =zuoziService.selectnum(tid);
		 PrintWriter pw=response.getWriter();
		 pw.print(i);
	}
}
